package com.ayg.controller;

import com.ayg.pojo.Cost;
import com.ayg.service.CostSerVer;
import com.ayg.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/cost")
public class CostController {
    @Autowired
    private CostSerVer costSerVer;

    @PostMapping("/addCost")
    public SysResult AddCost(@RequestBody Cost cost){
        costSerVer.addCost(cost);
        return SysResult.success();
    }
    @GetMapping("/getCost")
    public SysResult GetCost(){
        List<Cost> list= costSerVer.getCost();
        return SysResult.success(list);

    }

    /**
     * 业务分析: 根据用户ID查询数据库.
     * URL地址: /cost/{costId}
     * 返回值: SysResult对象
     */
    @GetMapping("/{costId}")
    public SysResult getCostById(@PathVariable Integer costId){
        Cost cost = costSerVer.getCostById(costId);
        return SysResult.success(cost);
    }

    @PutMapping ("/updateCost")
    public SysResult upCost(@RequestBody Cost cost){
        costSerVer.updateCost(cost);
        return SysResult.success();
    }


    @DeleteMapping("/{costId}")
    public SysResult deleteCost(@PathVariable Integer costId){
        costSerVer.deleteCost(costId);
        return SysResult.success();
    }
}

